# -*- coding: utf-8 -*-
# @Author: bao
# @Date:   2017-05-12 09:41:40
# @Last Modified by:   bao
# @Last Modified time: 2017-05-12 22:45:42
import os
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from matplotlib.font_manager import FontProperties
from matplotlib import gridspec
from matplotlib import rcParams

rcParams['font.family'] = 'times new roman'
rcParams['font.size'] = 14
fig = plt.figure(figsize=(5.8,3.5))
ax = plt.axes()

overhead = []
counter = 0

with open("300ToR_12Port_600Flows.txt", 'r') as f:
	for line in f.readlines():
		split = line.split()
		time = float(split[-1].split(':')[-1])*1000
		counter += 1
		if counter%2==0:
			overhead.append(time)
		print time

'''
with open("200ToR_8Port_600Flows.txt", 'r') as f:
	for line in f.readlines():
		split = line.split()
		time = float(split[-1].split(':')[-1])*1000
		if counter == 0:
			overhead.append(time)
		else:
			mid_time = 
			overhead.append()
		counter += 1
		if counter%2==0:
			overhead.append(time)
		print time
'''	
x = np.arange(len(overhead))
y = np.array(overhead)
z1 = np.polyfit(x, y, 4)#用3次多项式拟合
p1 = np.poly1d(z1)
yvals=p1(x)#也可以使用yvals=np.polyval(z1,x)
plt.plot(x, overhead, '.b', ms =2, label='polyfit values')
plt.plot(x, yvals, 'r', lw = 0.8, ls='--',  label='polyfit values')
plt.ylim(0, 200)
plt.xlabel("Multicast Flows Number")
plt.xticks((0, 50, 100, 150, 200, 250), (0, 100, 200, 300, 400, 500))
plt.ylabel("Runtime (ms)")
ax.yaxis.grid(zorder=0, ls='--')
plt.subplots_adjust(bottom=0.15, top=0.95, left=0.12, right=0.94)
plt.savefig('overhead.pdf')
plt.show()